#!/usr/bin/python
# coding: utf-8

import platform
import os

'''
 配置pip镜像加快下载速度！
'''


def write(fileDirPath,filePath):
    if not os.path.isdir(fileDirPath):
        os.mkdir(fileDirPath)
    with open(filePath,"w")as f:
        f.write("[global]\nindex-url=https://pypi.tuna.tsinghua.edu.cn/simple/\n[install]\ntrusted-host=pypi.tuna.tsinghua.edu.cn\n")
    print ("Configuration is complete")



if __name__ == "__main__":
    os_type = platform.system()
    if "Linux" == os_type:
        fileDirPath = "{}/.pip".format(os.path.expanduser('~'))
        filePath = "{}/pip.conf".format(fileDirPath)
        write(fileDirPath,filePath)
    elif "Windows" == os_type:
        fileDirPath = "{}\\.pip".format(os.path.expanduser('~'))
        filePath = "{}\\pip.ini".format(fileDirPath)
        write(fileDirPath,filePath)
    else:
        exit("Your platform is unknow!")



